package com.spzx.product;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spzx.common.security.annotation.EnableCustomConfig;
import com.spzx.common.security.annotation.EnableRyFeignClients;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.mapper.ProductSkuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

/**
 * @author LOGIN
 * @title SpzxProductApplication
 * @create 2025/7/17 15:08
 * @description
 */
@EnableCustomConfig
@EnableRyFeignClients
@SpringBootApplication
public class SpzxProductApplication implements CommandLineRunner // CommandLineRunner 接口可以在启动类中启动时，执行 run(String... args) 方法
{
    public static void main(String[] args)
    {
        SpringApplication.run(SpzxProductApplication.class, args);
        System.out.println("(♥◠‿◠)ﾉﾞ  系统模块启动成功   ლ(´ڡ`ლ)ﾞ  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
    }
    @Autowired
    private ProductSkuMapper productSkuMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("运行成功 run方法执行");

        //查询productSku中的所有数据，并将id存入bitMap中
        LambdaQueryWrapper<ProductSku> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductSku::getStatus,1);//查询所有状态为1的数据，1表示商品已发布
        queryWrapper.select(ProductSku::getId); //“只” 查询id字段
        List<Object> idList = productSkuMapper.selectObjs(queryWrapper); //将查询结果以List<Object>的形式（列表）返回，每个元素都是一个商品SKU的ID
        System.out.println("查询到的商品sku = " + idList);
        for (Object id : idList) {
            redisTemplate.opsForValue().setBit("product:sku:ids", (Long) id, true); //将商品SKU的ID添加到Redis的bitmap中。
        }
    }
}